package com.yanqu.road.server.cmd.activity.jiuzhou.cross;

import com.yanqu.road.entity.enums.eLogMoneyType;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.jiuzhou.CrossJiuZhouProto;
import com.yanqu.road.pb.activity.jiuzhou.JiuZhouProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.player.CurrencyModule;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameProtocol;
import com.yanqu.road.utils.string.StringUtils;

@Cmd(code = GameProtocol.S_JIU_ZHOU_SETTLE_FROM_CROSS, desc = "结算数据返回本服")
public class JiuZhouSettleFromCross extends AbstractCommand {

    private CrossJiuZhouProto.CrossJiuZhouGetSettleRewardRespMsg respMsg;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        respMsg = CrossJiuZhouProto.CrossJiuZhouGetSettleRewardRespMsg.parseFrom(packet.getBytes());
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        JiuZhouProto.JiuZhouGetSettleRewardRespMsg.Builder builder = JiuZhouProto.JiuZhouGetSettleRewardRespMsg.newBuilder();
        builder.setRet(respMsg.getRet());
        if (respMsg.getRet() == 0) {
            builder.setReward(respMsg.getReward());
            // 发奖
            if (!StringUtils.isNullOrEmpty(respMsg.getReward())) {
                player.getModule(CurrencyModule.class).addCurrency(respMsg.getReward(), eLogMoneyType.JiuZhou, eLogMoneyType.JiuZhouSettleReward);
            }
        }
        player.sendPacket(ClientProtocol.U_JIU_ZHOU_GET_SETTLE_REWARD, builder);
    }

    @Override
    public void sendData(GamePlayer player) {

    }
}
